ModEditor.Windows.RenameObject = {}

function ModEditor.Windows.RenameObject.New()
	local obj = ModEditor.GUI.BasicWindow:New()
	obj:Apply({{"Caption","Rename Objects"},{"X",10},{"Y",10},{"Width",250},{"Height",270},{"ShowFullWindow",true},{"Visible",true}})
	obj.ObjectName = ModEditor.GUI.EditBox:New(obj)
	obj.ObjectName:Apply({{"X",10},{"Y",30},{"Width",obj.Width-20},{"Height",20},{"MaxLength",16}})
	obj.OkButton = ModEditor.GUI.Button:New(obj)
	function obj.OkButton:OnClick()
		if self.Parent.ObjectName.Text ~= "" then
			local objects = {}
			for i = 1,#ModEditor.Windows.ObjectControl.ObjectList.Items do
				if ModEditor.Windows.ObjectControl.ObjectList.Items[i][2] then
					table.insert(objects,i)
				end
			end
			local name = self.Parent.ObjectName.Text
			local tempname
			local id = 0
			for d = 1,#objects do
				local ended
				while not ended do
					if id == 0 then
						tempname = name
					else
						tempname = name..id
					end
					ended = true
					for i = 1,#ModEditor.ObjectList do
						if ModEditor.ObjectList[i].Name == tempname then
							id = id + 1
							ended = false
						end
					end
				end
				ModEditor.ObjectList[objects[d]].Name = tempname
				ModEditor.Windows.ObjectControl.ObjectList.Items[objects[d]][1] = tempname
			end
			ModEditor.Windows.Remove(self.Parent.Id)
			ModEditor.Windows.ObjectControl.Child = nil
		end
	end
	obj.OkButton:Apply({{"X",10},{"Y",240},{"Width",22},{"Height",20},{"Caption","Ok"}})
	obj.CancelButton = ModEditor.GUI.Button:New(obj)
	function obj.CancelButton:OnClick()
		ModEditor.Windows.ObjectControl.Child = nil
		ModEditor.Windows.Remove(self.Parent.Id)
	end
	obj.CancelButton:Apply({{"X",42},{"Y",240},{"Width",52},{"Height",20},{"Caption","Cancel"}})
	obj:AddControl(obj.OkButton)
	obj:AddControl(obj.CancelButton)
	obj:AddControl(obj.ObjectName)
	ModEditor.Windows.Add(obj)
	ModEditor.Windows.Activate(obj.Id)
	return obj
end
